// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedVehicleStory;

import zombie.core.Rand;
import zombie.iso.IsoChunk;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMetaGrid;
import zombie.iso.Vector2;
import zombie.vehicles.BaseVehicle;
import zombie.vehicles.VehiclePart;

public final class RVSPoliceBlockade extends RandomizedVehicleStoryBase {
    public RVSPoliceBlockade() {
        this.name = "Police Blockade";
        this.minZoneWidth = 8;
        this.minZoneHeight = 8;
        this.setChance(3);
        this.setMaximumDays(30);
    }

    @Override
    public void randomizeVehicleStory(IsoMetaGrid.Zone zone, IsoChunk chunk) {
        this.callVehicleStorySpawner(zone, chunk, 0.0F);
    }

    @Override
    public boolean initVehicleStorySpawner(IsoMetaGrid.Zone zone, IsoChunk chunk, boolean debug) {
        VehicleStorySpawner vehicleStorySpawner = VehicleStorySpawner.getInstance();
        vehicleStorySpawner.clear();
        float float0 = (float) (Math.PI / 18);
        if (debug) {
            float0 = 0.0F;
        }

        float float1 = 1.5F;
        float float2 = 1.0F;
        if (this.zoneWidth >= 10) {
            float1 = 2.5F;
            float2 = 0.0F;
        }

        IsoDirections isoDirections = Rand.NextBool(2) ? IsoDirections.W : IsoDirections.E;
        Vector2 vector2 = isoDirections.ToVector();
        vector2.rotate(Rand.Next(-float0, float0));
        vehicleStorySpawner.addElement("vehicle1", -float1, float2, vector2.getDirection(), 2.0F, 5.0F);
        vector2 = isoDirections.RotLeft(4).ToVector();
        vector2.rotate(Rand.Next(-float0, float0));
        vehicleStorySpawner.addElement("vehicle2", float1, -float2, vector2.getDirection(), 2.0F, 5.0F);
        String string = "Base.CarLightsPolice";
        if (Rand.NextBool(3)) {
            string = "Base.PickUpVanLightsPolice";
        }

        vehicleStorySpawner.setParameter("zone", zone);
        vehicleStorySpawner.setParameter("script", string);
        return true;
    }

    @Override
    public void spawnElement(VehicleStorySpawner spawner, VehicleStorySpawner.Element element) {
        IsoGridSquare isoGridSquare = element.square;
        if (isoGridSquare != null) {
            float _float = element.z;
            IsoMetaGrid.Zone zone = spawner.getParameter("zone", IsoMetaGrid.Zone.class);
            String string0 = spawner.getParameterString("script");
            String string1 = element.id;
            switch (string1) {
                case "vehicle1":
                case "vehicle2":
                    BaseVehicle baseVehicle = this.addVehicle(
                        zone, element.position.x, element.position.y, _float, element.direction, null, string0, null, null
                    );
                    if (baseVehicle != null) {
                        if (Rand.NextBool(3)) {
                            baseVehicle.setHeadlightsOn(true);
                            baseVehicle.setLightbarLightsMode(2);
                            VehiclePart vehiclePart = baseVehicle.getBattery();
                            if (vehiclePart != null) {
                                vehiclePart.setLastUpdated(0.0F);
                            }
                        }

                        this.addZombiesOnVehicle(Rand.Next(2, 4), "police", null, baseVehicle);
                    }
            }
        }
    }
}
